<template>
  <div>
    <button class="bbutton" @click="returnNM" style="float: right">
      返回上一级
    </button>
    <el-table :data="idtabledatas" border>
      <el-table-column label="id">
        <template slot-scope="scope">
          <el-input
            placeholder="请输入内容"
            v-show="scope.row.show"
            v-model="scope.row.tab1"
          ></el-input>
          <span v-show="!scope.row.show">{{ scope.row.id }}</span>
        </template>
      </el-table-column>
    </el-table>
    <el-table :data="titletabledatas" border>
      <el-table-column label="title">
        <template slot-scope="scope">
          <el-input
            placeholder="请输入内容"
            v-show="scope.row.show"
            v-model="scope.row.title"
          ></el-input>
          <span v-show="!scope.row.show">{{ scope.row.title }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button @click="scope.row.show = true">编辑</el-button>
          <el-button
            @click="
              (scope.row.show = false),
                savedata('title', titletabledatas[0].title)
            "
            >保存</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-table :data="sourcetabledatas" border>
      <el-table-column label="source">
        <template slot-scope="scope">
          <el-input
            placeholder="请输入内容"
            v-show="scope.row.show"
            v-model="scope.row.source"
          ></el-input>
          <span v-show="!scope.row.show">{{ scope.row.source }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button @click="scope.row.show = true">编辑</el-button>
          <el-button
            @click="
              (scope.row.show = false),
                savedata('source', sourcetabledatas[0].source)
            "
            >保存</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-table :data="urltabledatas" border>
      <el-table-column label="url">
        <template slot-scope="scope">
          <el-input
            placeholder="请输入内容"
            v-show="scope.row.show"
            v-model="scope.row.url"
          ></el-input>
          <span v-show="!scope.row.show">{{ scope.row.url }}</span>
        </template>
      </el-table-column>
    </el-table>
    <el-table :data="publish_timetabledatas" border>
      <el-table-column label="publish_time">
        <template slot-scope="scope">
          <el-input
            placeholder="请输入内容"
            v-show="scope.row.show"
            v-model="scope.row.publish_time"
          ></el-input>
          <span v-show="!scope.row.show">{{ scope.row.publish_time }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button @click="scope.row.show = true">编辑</el-button>
          <el-button
            @click="
              (scope.row.show = false),
                savedata('publish_time', publish_timetabledatas[0].publish_time)
            "
            >保存</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-table :data="categorytabledatas" border>
      <el-table-column label="category">
        <template slot-scope="scope">
          <el-input
            placeholder="请输入内容"
            v-show="scope.row.show"
            v-model="scope.row.category"
          ></el-input>
          <span v-show="!scope.row.show">{{ scope.row.category }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button @click="scope.row.show = true">编辑</el-button>
          <el-button
            @click="
              (scope.row.show = false),
                savedata('category', categorytabledatas[0].category)
            "
            >保存</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-table :data="contenttabledatas" border>
      <el-table-column label="content" width="1000">
        <template slot-scope="scope">
          <el-input
            placeholder="请输入内容"
            v-show="scope.row.show"
            v-model="scope.row.content"
          ></el-input>
          <span v-show="!scope.row.show">{{ scope.row.content }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button @click="scope.row.show = true">编辑</el-button>
          <el-button
            @click="
              (scope.row.show = false),
                savedata('content', contenttabledatas[0].content)
            "
            >保存</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-table :data="keywordstabledatas" border>
      <el-table-column label="keywords">
        <template slot-scope="scope">
          <el-input
            placeholder="请输入内容"
            v-show="scope.row.show"
            v-model="scope.row.keywords"
          ></el-input>
          <span v-show="!scope.row.show">{{ scope.row.keywords }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button @click="scope.row.show = true">编辑</el-button>
          <el-button
            @click="
              (scope.row.show = false),
                savedata('keywords', keywordstabledatas[0].keywords)
            "
            >保存</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-table :data="sentimenttabledatas" border>
      <el-table-column label="sentiment">
        <template slot-scope="scope">
          <el-input
            placeholder="请输入内容"
            v-show="scope.row.show"
            v-model="scope.row.sentiment"
          ></el-input>
          <span v-show="!scope.row.show">{{ scope.row.sentiment }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button @click="scope.row.show = true">编辑</el-button>
          <el-button
            @click="
              (scope.row.show = false),
                savedata('sentiment', sentimenttabledatas[0].sentiment)
            "
            >保存</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
export default {
  data() {
    var id1 = this.$route.query.id;
    var title1 = this.$route.query.title;
    var source1 = this.$route.query.source;
    var url1 = this.$route.query.url;
    var publish_time1 = this.$route.query.publish_time;
    var category1 = this.$route.query.category;
    var content1 = this.$route.query.content;
    var keywords1 = this.$route.query.keywords;
    var sentiment1 = this.$route.query.sentiment;
    return {
      idtabledatas: [{ id: id1 }],
      titletabledatas: [{ title: title1, show: false }],
      sourcetabledatas: [{ source: source1, show: false }],
      urltabledatas: [{ url: url1 }],
      publish_timetabledatas: [{ publish_time: publish_time1, show: false }],
      categorytabledatas: [{ category: category1, show: false }],
      contenttabledatas: [{ content: content1, show: false }],
      keywordstabledatas: [{ keywords: keywords1, show: false }],
      sentimenttabledatas: [{ sentiment: sentiment1, show: false }],
    };
  },
  methods: {
    savedata(label, content) {
      const self = this;
      var id1 = this.$route.query.id;
      // console.log("属性:",label,"内容：",content,"id：",id1);
      self
        .$axios({
          method: "post",
          url: "/api/news/edit",
          data: {
            news_id: id1,
            name: label,
            cont: content,
          },
          headers: {
            Authorization: window.sessionStorage.getItem("token"),
          },
        })
        .then((res) => {
          // console.log("返回的东西：",res)
          if (res.data.statusCode == 0) {
            alert(res.data.message);
            // window.location.replace('/mainlayout/newsManagement')
            this.$router.push({
              name: "newsManagement",
            });
          } else {
            alert(res.data.message);
          }
        });
    },
    returnNM() {
      // window.location.replace('/mainlayout/NewsManagement')
      this.$router.push({
        name: "newsManagement",
      });
    },
  },
};
</script>